<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="media/layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<form class="layui-form" action=""  lay-filter="example">
    <div class="layui-form-item">

        <div class="layui-form-item">
            <label class="layui-form-label">收件人</label>
            <div class="layui-input-block">
                <input type="text" name="email" lay-verify="email" autocomplete="off" placeholder="收件人邮箱"class="layui-input">
            </div>
        </div>


    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">主题</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">正文</label>
        <div class="layui-input-block">
            <input type="text" name="text" lay-verify="title" autocomplete="off" placeholder="请输入内容" class="layui-textarea">

        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">

            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1" onclick="cl()">发送</button>

        </div>
    </div>

</form>
<script src="media/js/jquery.min.js"></script>
<script type="text/javascript" src="media/layui/layui.js"></script>

    <script>

    layui.use(['form', 'layedit', 'laydate'], function() {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            ,$ = layui.jquery;


        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            }

            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        form.on('submit(demo1)', function(){
            $.ajax({

                url:"sendEmail.do",
                type:"POST",

                data:$('form').serialize(),
                success:function (res) {
                    layer.msg("发送成功")
                }


            })
            return false;
        });

    });

    </script>


</body>
</html>